// import {postlink} from"@a/postapi.js"
import {loggetlink} from"@a/loggetapi.js"
import {postlink} from"@a/postapi.js"

export let elsem={
    state: {
      // 登录状态
      login:false,
      // 用户名
      username:null,
      // 用户手机号
      phone:null
      },
      mutations: {
        loglog(state,payload){
          state.login = true
          state.username = payload.username
          state.phone = payload.phone
          console.log("登录成功")
        },
        logexit(state){
          state.login = true
        }
      },
      actions: {

        // 登录
        postlink(context,payload){
          console.log(payload.url,payload.phone)
          postlink(payload.url,payload.phone).then((ok)=>{
            console.log(ok)
            console.log(ok.data.token,payload.phone,ok.data.username)
            // console.log(ok.data.data.token)
            window.localStorage.setItem("login","true")
            window.localStorage.setItem("token",ok.data.token);
            window.localStorage.setItem("phone",payload.phone);
            window.localStorage.setItem("username",ok.data.username);
            context.commit("loglog",ok.data)
          }).catch((err)=>{
            console.log(err)
          })
        },
        // 注册
        reglink(context,payload){
          console.log(payload.url,payload.data)
          postlink(payload.url,payload.data).then((ok)=>{
            console.log(ok)
            window.localStorage.setItem("login","true")
            window.localStorage.setItem("token",ok.data.token);
            window.localStorage.setItem("phone",payload.data.phone);
            window.localStorage.setItem("username",payload.data.username);
            context.commit("loglog",ok.data)
          }).catch((err)=>{
            console.log(err)
          })
        },
        // 验证码
        yzmget(context,payload){
          console.log(context,payload.url)
          loggetlink(payload.url).then((ok)=>{
            console.log(ok)
          }).catch((err)=>{
            console.log(err)
          })
        }
      },
}